<?php
class SettingAction extends Action {

    public function _initialize() {
        $Config = A('Config');
        $Config->checkLogIn();
        if (!in_array(ACTION_NAME, array('editPassword'))) {
            $Config->checkUserLevel(array('1'));
        } else {
            $Config->checkUserLevel(array('1', '2', '3'));
        }
    }
    
    /* 系统设置 */
    public function edit() {
        $Setting = M('setting');
        $setting = $Setting->find(1);
        
        $this->assign('setting', $setting);
        $this->display();
    }
    
    /* 保存系统设置 */
    public function update() {
        if (isset($_POST['submitted'])) {
            $Setting = D('Setting');
            
            if ($Setting->create()) {
                if (false !== $Setting->save()) {
                    $this->success('成功编辑系统设置！');
                } else {
                    $this->error('编辑系统设置失败！');
                }
            } else {
                $this->error($Setting->getError());
            }
        }
    }
    
    // 更改密码
    public function editPassword() {
        $this->display();
    }
    
}
?>